package my.example.samplegridview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class register extends Activity{
	
	register _self;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.register);
		
		_self = this;
		
		Button backbutton = (Button) findViewById(R.id.registerback);
		backbutton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				finish();
			}
			
		});
		
		final EditText registerconfirmpassword = (EditText) findViewById(R.id.registerconfirmpassword);
		final EditText registerpassword = (EditText) findViewById(R.id.registerpassword);
		final EditText firstname = (EditText) findViewById(R.id.registerfirstname);
		final EditText lastname = (EditText) findViewById(R.id.registerlastname);
		final EditText emailaddress = (EditText) findViewById(R.id.registeremailaddress);
		
		Button submitbutton = (Button) findViewById(R.id.registersubmit);
		submitbutton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				String orierr = "Errors : \n";
				String errorText = "Errors : \n";
				
				if(firstname.getText().toString().trim().length() == 0){
					errorText += "   * First Name need to be fill up\n";
				}
				
				if(lastname.getText().toString().trim().length() == 0){
					errorText += "   * Last Name need to be fill up\n";
				}
				
				if(emailaddress.getText().toString().trim().length() == 0){
					errorText += "   * Email Address need to be fill up\n";
				}
				
				if(registerpassword.getText().toString().trim().length() == 0){
					errorText += "   * Password need to be fill up\n";
				}
				
				if(registerpassword.getText().toString().trim().length() < 7){
					errorText += "   * Password length cannot be less than 6 characters.\n";
				}
				
				if(registerpassword.getText().toString().compareTo(registerconfirmpassword.getText().toString()) != 0){
					errorText += "   * Password and confirm password field are not match.\n";
				}
				
				if(orierr.compareTo(errorText) != 0){
					Toast.makeText(_self, errorText, Toast.LENGTH_SHORT).show();
				}
				else{
					Toast.makeText(_self, "Register successfully. You will receive a confirmation email shortly.", Toast.LENGTH_SHORT).show();
					finish();
				}
			}
			
		});
	}
}
